<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<style type="text/css">
						.head {
				height: 40px;
			}
			#head {
				line-height: 40px;
			}
			.head-img {
				width: 40px;
				height: 40px;
			}
			#head-img1 {
				position: absolute;
				bottom: 10px;
				right: 40px;
				width: 40px;
				height: 40px;
			}
			.update {
				font-style: normal;
				color: #999999;
				margin-right: -25px;
				font-size: 15px
			}
			/*ul span{
				background:#CCCCCC;
				height: 100%;padding: 20px;
			}*/
		</style>
	</head>

	<body>
		<script src="../../js/mui.min.js"></script>
		<!--<script src="../../js/jquery-3.3.1.js"></script>-->
		<script type="text/javascript">
			mui.init();
			window.addEventListener('refresh', function(e){//执行刷新
			  location.reload(); 
			  });
			  
		</script>
		<div class="mui-content">
			<div class="mui-page-content">
				<div class="mui-scroll-wrapper">
					<div class="mui-scroll">
						 <!--<ul class="list">
            <li class='mui-table-view-cell mui-media'>
                 <img id="headimg" class="headimg" src=''  height="150"  width="150">
                <p><a  class="imageup 1">上传图片1</a> </p>
                <p><button onclick="upload();" class='button'> 提交</button></p>
            </li></ul>-->
						<ul class="mui-table-view list">
							<li class="mui-table-view-cell infoName" id="image"  onclick="image()">
							    <img id="headimg" class="headimg"  height="50"  width="50" src="../../images/iconfont-tianjia.png"  onerror="this.onerror=null;this.src='../../images/logo.png'"/><span style=" float:right;padding: 15px;">上传头像</span>
							</li>
							<li class="mui-table-view-cell">
								<a class="mui-navigate-right">姓名<span id="username" onclick="updata(this.id)" class="mui-pull-right">Hbuilder</span></a>
							</li>
							<li class="mui-table-view-cell">
								<a>账号<span id="account" class="mui-pull-right">hbuilder@dcloud.io</span></a>
							</li>
						</ul>
						<!--<button onclick="alertDIV('sendSms',['信息','手机','验证'])">出来</button>-->
						<ul class="mui-table-view">
							<li class="mui-table-view-cell">
								<a>QQ号<span id="qq" onclick="updata(this.id)" class="mui-pull-right ">88888888</span></a>
							</li>
							<li class="mui-table-view-cell">
								<a>手机号<span id="mobile" onclick="alertDIV('sendSms',['信息','手机','验证'])" class="mui-pull-right ">18601234567</span></a>
							</li>
							<li class="mui-table-view-cell">
								<a>邮箱地址<span id="email" onclick="updata(this.id)" class="mui-pull-right">hbuilder@dcloud.io</span></a>
							</li>
							<li class="mui-table-view-cell">
								<a>联系地址<span id="address" onclick="updata(this.id)" class="mui-pull-right">hbuilder@dcloud.io</span></a>
							</li>
							<!--<li  class="mui-table-view-cell">
							<a id="authentication" onclick="goto('user','admin','authentication','')">实名认证 </a>
							</li>-->
							<div style="display: block;"></div>
						</ul>
					</div>
				</div>
			</div>
		</div>
		
				
			
		<script src="../../js/app.js"></script>
		<script src="../../Plugin/image/asset/transform.js"></script>
    <script src="../../Plugin/image/asset/alloy-finger.js"></script>
    <script src="../../Plugin/image/alloy-crop.js"></script>
    <script src="../../js/check.js"></script>
    <script src="../../Plugin/js/alertDIV.js"></script>
    <!--<script src="Plugin/imgupload.js"></script>-->
<script type="text/javascript">	

//上传图片返回触发方式
	window.addEventListener('renovate', function(e){
		//裁剪后返回的64base图片显示在image标签下的img
		document.getElementById('image').getElementsByTagName('img')[0].src=e.detail.image;
				//主图裁剪上传返回数据执行更新
//			  location.reload(); //刷新
					apptoken['type']='headimg',//修改的类型
                  	apptoken['val']=e.detail.image,//值
                  	apptoken['act']='modify'//修改

           upload(apptoken);//上传服务器
});
function image() {
		width=200;
		height=200;
		localStorage.image='{"src":"'+document.getElementById('headimg').src+'","width":'+width+',"height":'+height+'}';
		mui.openWindow('../../Plugin/image/base64.html');
//mui.openWindow('../../Plugin/image/image.html');//不裁剪
	};
			
function sendSms(e){
	if(e[0] || e[0]=='1'){
		if(isMobile(e[1])===false){
    		alert(e[1]+'您输入的手机号码有误'+isMobile(e[1]));
  			return false;
	    }else{
				alert(e);
				apptoken['act']='getCode';
				apptoken['val']=e[1];//值
				apptoken['code']=e[2];//值
				mui.post(home.hos+'/user/admin',apptoken,function(data){
//					alert(data);
					if(data!==200){
						mui.prompt('', '','请输入手机验证码' ,['取消','确认'], function(e1) {
			        		if (e1.index == 1){
			        		  ///ajax请求数据类型
			                  apptoken['type']='mobile';//修改的类型
			                  apptoken['code']=e1.value;//值
			                  apptoken['act']='modify';//修改
			           		  upload(apptoken);//上传服务器
			           }
			//      		
			        	},'div')
					}else{
						alert('验证码有误');
					}
						
				})
		}
	}else{
	alert('取消');
	}
}
//更改文本信息资料
function updata(thisid){
//修改类型用来获取图片显示出来和传送post数据调用
		var btnArray = ['取消','确认'];
		if(thisid=='mobile'){
			murl = home.hos+"/user/admin";//服务器地址
			mui.prompt('', '','请输入新手机号' , ['取消','发送验证码'], function(e) {
		        if (e.index == 1){
		        	if(isMobile(e.value)===false){
		        		alert(e.value+'您输入的手机号码有误'+isMobile(e.value));
		//      		return false;
		        	}else{
		        		  sendSms(e.value);
		//      		  return false;
		        	}
		        } else {
		           alert('你点了取消按钮');
		        }
		    },'div')
		}else{
			murl = home.hos+"/user/admin";//服务器地址
    mui.prompt('请输入你要修改的内容', document.getElementById(thisid).innerText,'' , btnArray, function(e) {
        if (e.index == 1) {
             ///ajax请求数据类型
                  apptoken['type']=thisid,//修改的类型
                  apptoken['val']=e.value,//值
                  apptoken['act']='modify'//修改

           upload(apptoken);//上传服务器
        } else {
           alert('你点了取消按钮');
        }
    },'div')
		}
}
// 连接服务器修改
function upload(data){ 
	murl = home.hos+"/user/admin";//服务器地址
     var wt=plus.nativeUI.showWaiting();
//   alert(JSON.stringify(data));
//   return false;
            //发送数据    
             mui.ajax(murl,{
                    data:data,
                    dataType:'text',
                    type:'POST',
                    timeout:5000,
                    success:function(data){
//                  	alert(JSON.stringify(apptoken)+'服务器'+JSON.stringify(data));
                    	data =JSON.parse(data);
							 wt.close();//关闭加载 
							   if(data.status==""){
							var btnArray = ['否', '是'];
							    mui.confirm('是否尝试从新登陆？', '授权失败', btnArray, function(e) {
							        if (e.index == 1) {
							        	mui.openWindow('login.html');
							//          alert('确认');
							        } else {
							//           alert('取消');
							return false;
							        }
							    })
							   }
                        if(data.status==200){
                  my[apptoken['type']]=data[apptoken['type']]; 
//                alert("my."+data[thisid]);
                var xxmy="";
        for(var key in my){  
            try{  
                var value = eval("my['" +  key +"']");  
                xxmy+='"'+key+'":"'+value+'",';
            }catch(e){} 
        }  
		   xxmy = '{'+xxmy.substring(0, xxmy.lastIndexOf(","))+'}'; 
		   if(apptoken['type']!="headimg"){
		   	document.getElementById(apptoken['type']).innerText=data[apptoken['type']];
		   }else{
		   	document.getElementById("headimg").src=home.uploadsuser+'/min'+data[apptoken['type']];
		   }
//                 info.innerText = e.value;//把值替换给窗口
                        	localStorage.setItem("my",xxmy);
                            //成功
                            plus.ui.toast("修改成功");
                        }else{
                            //失败
                            plus.ui.toast("修改失败");
                        }
                   }
                })
}
//mui.ready(function() {})
if(status=1){
document.getElementById("username").innerHTML=my.username+"[+]";
document.getElementById("account").innerHTML=my.account+"";
document.getElementById("headimg").src=home.uploadsuser+'/min'+my.headimg;
document.getElementById("mobile").innerHTML=my.mobile+"[+]";
document.getElementById("qq").innerHTML=my.qq+"[+]";
document.getElementById("email").innerHTML=my.email+"[+]";
document.getElementById("address").innerHTML=my.address+"[+]";
}
        </script> 
        
	</body>

</html>